package com.ruoyi.car.controller.parts;

import java.util.List;

import com.ruoyi.car.service.parts.ITbPartMotorModelService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.car.pojo.TbPartMotorModel;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

@Controller
@RequestMapping("/parts/motorModel")
public class TbPartMotorModelController extends BaseController {

    private String prefix = "parts/motorModel";

    @Autowired
    private ITbPartMotorModelService tbPartMotorModelService;

    @RequiresPermissions("parts:motorModel:view")
    @GetMapping()
    public String motorModel()
    {
        return prefix + "/motorModel";
    }

    @RequiresPermissions("parts:motorModel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbPartMotorModel tbPartMotorModel)
    {
        startPage();
        List<TbPartMotorModel> list = tbPartMotorModelService.selectTbPartMotorModelList(tbPartMotorModel);
        return getDataTable(list);
    }

    @RequiresPermissions("parts:motorModel:export")
    @Log(title = "驱动电机型号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbPartMotorModel tbPartMotorModel)
    {
        List<TbPartMotorModel> list = tbPartMotorModelService.selectTbPartMotorModelList(tbPartMotorModel);
        ExcelUtil<TbPartMotorModel> util = new ExcelUtil<TbPartMotorModel>(TbPartMotorModel.class);
        return util.exportExcel(list, "motorModel");
    }

    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @RequiresPermissions("parts:motorModel:add")
    @Log(title = "驱动电机型号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbPartMotorModel tbPartMotorModel)
    {
        return toAjax(tbPartMotorModelService.insertTbPartMotorModel(tbPartMotorModel));
    }

    @GetMapping("/edit/{motorModelId}")
    public String edit(@PathVariable("motorModelId") Long motorModelId, ModelMap mmap)
    {
        TbPartMotorModel tbPartMotorModel = tbPartMotorModelService.selectTbPartMotorModelById(motorModelId);
        mmap.put("tbPartMotorModel", tbPartMotorModel);
        return prefix + "/edit";
    }

    @RequiresPermissions("parts:motorModel:edit")
    @Log(title = "驱动电机型号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbPartMotorModel tbPartMotorModel)
    {
        return toAjax(tbPartMotorModelService.updateTbPartMotorModel(tbPartMotorModel));
    }

    @RequiresPermissions("parts:motorModel:remove")
    @Log(title = "驱动电机型号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbPartMotorModelService.deleteTbPartMotorModelByIds(ids));
    }
}
